package zhtt.controller;

import com.gitee.zhtt.base.DateTimeUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import zhtt.entity.Article;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping(value = "/test")
public class TestController {

    @GetMapping(value = "/list.html")
    public String test(Model model){
        System.out.println(DateTimeUtils.format(new Date())+"  FreeMarker + Nginx实现页面静态化");
        List<Article> list = new ArrayList<>();
        list.add(new Article("1","一个亿",18));
        list.add(new Article("2","店小二",20));
        list.add(new Article("3","泰山",22));
        list.add(new Article("4","李四",22));
        list.add(new Article("5","王五",22));
        list.add(new Article("6","赵六",22));
        list.add(new Article("7","鬼脚七",22));
        list.add(new Article("8","星八",22));
        list.add(new Article("9","一壶老酒",22));
        model.addAttribute("list",list);
        return "test";
    }

    @GetMapping("redirect")
    public void doLogin(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.sendRedirect("http://localhost:4000/dashboard");
    }

}
